<?php

Yii::import('application.models._base.BaseSectionHistory');

class SectionHistory extends BaseSectionHistory
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
    public function getContent($section_code,$type){
        $db = Yii::app()->db->createCommand();
        $info = $db->select('content')
            ->from('{{section_history}}')
            ->where('section_code=:section_code and type=:type',array(':section_code'=>$section_code,':type'=>$type))
            ->order('create_time desc')
            ->queryRow();
        return $info['content'];
    }
    public function getFindHistory($section_code,$type){
        return $this->find('section_code=:section_code and type=:type',array(':section_code'=>$section_code,'type'=>$type));
    }
    public function createData($section_code,$type,$content){
        $auth = Yii::app()->user->getState('user_auth');
        $db = new SectionHistory();
        $db->section_code = $section_code;
        $db->type = $type;
        $db->content = $content;
        $db->user_id = Yii::app()->user->id;
        $db->user_name = $auth['username'];
        $db->create_time = time();
        $db->save();
    }
    public function getInfo($section_code,$type){
        $db = Yii::app()->db->createCommand();
        $info = $db->select('content')
            ->from('{{section_history}}')
            ->where('section_code=:section_code and type=:type',array(':section_code'=>$section_code,':type'=>$type))
            ->order('create_time desc')
            ->queryRow();
        $meta_value = Xtutuquan::stripslashes($info['content']);
        $meta_value = (array) Xtutuquan::string2array($meta_value);
        return $meta_value;
    }

}